/**
 * fishing-spots apis
 */
import { post, get, put, del } from "../utils/request";

/**
 * fetch fishing spot list
 * @returns
 */
export async function fetchFishingSpotList() {
  const res = await get("/fishing-spot/own");

  return res.data || [];
}

/**
 * 保存或者更新信息
 * @param {*} data
 * @returns
 */
export async function saveFishingSpot(spotId, data) {
  data.id = undefined;
  if (spotId) {
    return updateFishingSpot(spotId, data);
  }
  return createishingSpot(data);
}

/**
 * save fishing spot
 * @param {Object} data - 钓场数据
 * @returns
 */
export async function createishingSpot(data) {
  const res = await post("/fishing-spot", data);
  return res;
}

/**
 * update fishing spot
 * @param {string} id - 钓场ID
 * @param {Object} data - 钓场数据
 * @returns
 */
export async function updateFishingSpot(id, data) {
  const res = await put(`/fishing-spot/${id}`, data);
  return res;
}

/**
 * delete fishing spot
 * @param {string} id - 钓场ID
 * @returns
 */
export async function deleteFishingSpot(id) {
  const res = await del(`/fishing-spot/${id}`);
  return res;
}

/**
 * get fishing spot by id
 * @param {string} id - 钓场ID
 * @returns
 */
export async function getFishingSpotById(id) {
  let spot = null;
  const res = await get(`/fishing-spot/${id}`);
  if (res.error) {
    return spot;
  }
  spot = res.data;
  return spot;
}
